package IO;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;

public class 字节流 {
    public static void main(String[] args) {
        method();
        method2();
    }
    //高效字节流
private static void method2(){

        OutputStream out=null;
        try {
            out=new BufferedOutputStream(new FileOutputStream("F:\\a\\2.txt",true));
            out.write(95);
            out.write(99);
            out.write(99);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                out.close();
            }catch (Exception e){
                e.printStackTrace();
            }
        }
}


    //普通字节流
    private static void method(){
        OutputStream out=null;
        try {
            out=new FileOutputStream("F:\\a\\2.txt",true);//如果第二个参数为true,表示追加,不覆盖
        //使用流对象--进行写出操作
            out.write(99);//对应ASCII码表中的a
            out.write(100);//对应ASCII码表中的b
            out.write(101);//对应ASCII码表中的c
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {//如果想要代码一定会执行,需要写在finally中
            out.close();  //关流  
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        
    }
}
